package com.liuheng.spzx.cart.controller;

import com.liuheng.spzx.cart.service.CartService;
import com.liuheng.spzx.model.entity.h5.CartInfo;
import com.liuheng.spzx.model.vo.common.Result;
import com.liuheng.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/order/cart")
public class CartController {
@Autowired
private CartService cartService;
    @GetMapping("auth/addToCart/{skuId}/{skuNum}")
    public Result addToCart(@PathVariable("skuId") Long skuId,
                             @PathVariable("skuNum") Integer skuNum) {
    cartService.addToCart(skuId, skuNum);
    return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/auth/cartList")
    public Result getCartList(){
       List<CartInfo> cartInfoList=cartService.getCartList();
       return Result.build(cartInfoList,ResultCodeEnum.SUCCESS);
    }
    @DeleteMapping("/auth/deleteCart/{skuId}")
    public Result deleteCartBySkuId(@PathVariable Long skuId){
        cartService.deleteCartBySkuId(skuId);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/auth/checkCart/{skuId}/{isChecked}")
    public Result checkCart(@PathVariable Long skuId,@PathVariable Integer isChecked){
        cartService.checkCart(skuId,isChecked);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/auth/allCheckCart/{isChecked}")
    public Result checkAllCart(@PathVariable Integer isChecked){
        cartService.checkAllCart(isChecked);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/auth/clearCart")
    public Result clearCart(){
        cartService.clearCart();
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    //远程调用接口，方便调用返回list集合
    @GetMapping(value = "/auth/getAllCkecked")
    public List<CartInfo> getAllChecked(){
        List<CartInfo> cartInfoList=cartService.getAllChecked();
       return cartInfoList;
    }
    @GetMapping(value = "/auth/deleteChecked")
    public Result deleteChecked() {
        cartService.deleteChecked() ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
}
